package com.ruoyi.web.controller.system;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.common.exception.ServiceException;
import io.swagger.annotations.ApiOperation;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.YhType;
import com.ruoyi.system.service.IYhTypeService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 烟盒类型Controller
 * 
 * @author ruoyi
 * @date 2023-06-06
 */
@Api(tags = "烟盒类型管理")
@RestController
@RequestMapping("/yh/type")
public class YhTypeController extends BaseController
{
    @Autowired
    private IYhTypeService yhTypeService;

    /**
     * 查询烟盒类型列表
     */
    @ApiOperation("获取烟盒类型列表")
    @PreAuthorize("@ss.hasPermi('yh:type:list')")
    @GetMapping("/list")
    public TableDataInfo list(YhType yhType)
    {
        startPage();
        List<YhType> list = yhTypeService.list(yhType.queryWrapper());
        return getDataTable(list);
    }

    /**
     * 导出烟盒类型列表
     */
    @ApiOperation("导出烟盒类型列表")
    @PreAuthorize("@ss.hasPermi('yh:type:export')")
    @Log(title = "烟盒类型", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, YhType yhType)
    {
        List<YhType> list = yhTypeService.list(yhType.queryWrapper());
        ExcelUtil<YhType> util = new ExcelUtil<YhType>(YhType.class);
        util.exportExcel(response, list, "烟盒类型数据");
    }

    /**
     * 获取烟盒类型详细信息
     */
    @ApiOperation("获取烟盒类型详细")
    @ApiImplicitParam(name = "id", value = "烟盒类型ID", required = true, dataType = "String", paramType = "path")
    @PreAuthorize("@ss.hasPermi('yh:type:list')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") String id)
    {
        return success(yhTypeService.getById(id));
    }

    /**
     * 新增烟盒类型
     */
    @ApiOperation("新增烟盒类型")
    @PreAuthorize("@ss.hasPermi('yh:type:add')")
    @Log(title = "烟盒类型", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody YhType yhType)
    {
        List<YhType> list = yhTypeService.list(yhType.queryWrapper());
        if(list.size() > 0){
            throw new ServiceException(yhType.getType() + "已存在！");
        }
        return toAjax(yhTypeService.save(yhType));
    }

    /**
     * 修改烟盒类型
     */
    @ApiOperation("更新烟盒类型")
    @PreAuthorize("@ss.hasPermi('yh:type:edit')")
    @Log(title = "烟盒类型", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody YhType yhType)
    {
        return toAjax(yhTypeService.updateById(yhType));
    }

    /**
     * 删除烟盒类型
     */
    @ApiOperation("删除用户信息")
    @ApiImplicitParam(name = "ids", value = "烟盒类型ID集合", required = true, dataType = "String", paramType = "path")
    @PreAuthorize("@ss.hasPermi('yh:type:remove')")
    @Log(title = "烟盒类型", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable List<String> ids)
    {
        return toAjax(yhTypeService.removeByIds(ids));
    }
}
